package com.bluesky.drcp.persistence.dao.hibernate;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.bluesky.drcp.business.ClientConfig;
import com.bluesky.drcp.persistence.dao.ClientConfigDao;

public class ClientConfigDaoImpl extends HibernateDaoSupport implements
		ClientConfigDao {
	public void insert(ClientConfig o) {
		/*
		 * Session session = getSession(); session.save(o); session.flush();
		 */
		getHibernateTemplate().save(o);
	}

	public void update(ClientConfig o) {
		getHibernateTemplate().update(o);
	}

	public void delete(String id) {
		ClientConfig o = getById(id);
		getHibernateTemplate().delete(o);
	}

	public ClientConfig getById(String id) {
		return (ClientConfig) getHibernateTemplate()
				.get(ClientConfig.class, id);
	}

	public String getId(String host, String module) {
		List list = getHibernateTemplate().find(
				"from ClientConfig where host=? and module=?",
				new Object[] { host, module });

		if(list.isEmpty())
			return null;
		else
		{
			return ((ClientConfig) list.get(0)).getId();
		}
	}

	public void deleteById(String id) {
		ClientConfig o = getById(id);
		getHibernateTemplate().delete(o);

	}
}
